<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="小区" prop="areaName">
        <el-select v-model="queryParams.areaName" placeholder="请输入小区" clearable size="small">
          <el-option v-for="(item, index) in areaIdOptions" :key="index" :label="item.areaName"
            :value="item.areaName" :disabled="item.disabled" ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="社区" prop="communityName">
        <el-select v-model="queryParams.communityName" placeholder="请输入社区" clearable :style="{width: '100%'}">
          <el-option v-for="(item, index) in communityOptions" :key="index" :label="item.communityName"
            :value="item.communityName" :disabled="item.disabled"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="维修内容" prop="infoName">
        <el-select v-model="queryParams.infoName" :style="{width: '100%'}" clearable placeholder="请选择维修内容">
          <el-option v-for="(item, index) in projectInfoOptions" :key="index" :disabled="item.disabled"
                     :label="item.infoName" :value="item.infoName"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="提交时间" prop="createDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.createDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择提交时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="认证状态" prop="informationSts">
        <el-select v-model="queryParams.informationSts" placeholder="请选择认证状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.HOUSE018"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          :disabled="pass"
          @click="handlePass"
          size="mini"
        >审批通过</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          :disabled="refuse"
          @click="handleRefuse"
          size="mini"
        >审批拒绝</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectRequestList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="小区名称" align="center" prop="areaName" />
      <el-table-column label="社区" align="center" prop="communityName" />
      <el-table-column label="申请书照片" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
        <span style="color:#007aff" @click="openCard(scope.row.requestPhotoHttp)">{{ scope.row.requestPhotoName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="现场照片1" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
        <span style="color:#007aff" @click="openCard(scope.row.sitePhotoHttp1)">{{ scope.row.sitePhotoName1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="现场照片2" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
        <span style="color:#007aff" @click="openCard(scope.row.sitePhotoHttp2)">{{ scope.row.sitePhotoName2 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="现场照片3" align="center" :show-overflow-tooltip="true">
        <template slot-scope="scope">
        <span style="color:#007aff" @click="openCard(scope.row.sitePhotoHttp3)">{{ scope.row.sitePhotoName3 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="维修内容" align="center" prop="infoName" />
      <el-table-column label="描述" align="center" prop="remark" :show-overflow-tooltip="true"/>
      <el-table-column label="提交时间" align="center" prop="createDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="认证状态" align="center" prop="informationSts">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.HOUSE018" :value="scope.row.informationSts"/>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog :title="titleCard" :visible.sync="showCard" width="500px" append-to-body>
     <div style="text-align:center">
     <img style="width:400px" :src="cardUrl" />
     </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="showCard=false">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProjectRequest,  housePass, houseRefuse ,getAreaInfo,getProjectInfoId,getCommunityId} from "@/api/house/projectRequest";

export default {
  name: "ProjectRequest",
  dicts: ['HOUSE018'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      pass: true,
      refuse: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 维修申请表格数据
      projectRequestList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaName: null,
        communityName: null,
        infoName: null,
        createDate: null,
        informationSts: null
      },
      cardUrl:'',
      titleCard:'',
      showCard:false,
      areaIdOptions:[{}],
      projectInfoOptions:[{}],
      communityOptions:[{}],
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.areaSelect();
    this.projectInfoSelect();
    this.communitySelect();
  },
  methods: {
    openCard(id,name){
        this.titleCard = name
        this.cardUrl=id;
        this.showCard=true;
    },
    /** 查询维修申请列表 */
    areaSelect(){
      getAreaInfo().then(response => {
        this.areaIdOptions = response.rows;
      });
    },
    communitySelect(){
      getCommunityId().then(response => {
        this.communityOptions = response.rows;
      });
    },
    projectInfoSelect() {
      getProjectInfoId().then(response => {
        this.projectInfoOptions = response.rows;
      });
    },
    getList() {
      this.loading = true;
      listProjectRequest(this.queryParams).then(response => {
        this.projectRequestList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        areaName: null,
        communityName: null,
        requestPhotoHttp: null,
        requestPhotoName: null,
        requestPhoto: null,
        sitePhotoHttp1: null,
        sitePhotoName1: null,
        sitePhoto1: null,
        sitePhotoHttp2: null,
        sitePhotoName2: null,
        sitePhoto2: null,
        sitePhotoHttp3: null,
        sitePhotoName3: null,
        sitePhoto3: null,
        infoName: null,
        remark: null,
        createDate: null,
        informationSts: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.pass = !selection.length;
      this.refuse = !selection.length;
      selection.map(item => {
        if(item.informationSts!=0){
          this.pass = true;
          this.refuse = true;
        }
      })
      this.ids = selection.map(item => item.id)
    },
    handlePass() {
       housePass(this.ids).then(response => {
           this.$modal.msgSuccess("执行成功");
           this.getList();
       });
     },
     handleRefuse() {
       houseRefuse(this.ids).then(response => {
           this.$modal.msgSuccess("执行成功");
           this.getList();
       });
     },
    /** 导出按钮操作 */
    handleExport() {
      this.download('house/projectRequest/export', {
        ...this.queryParams
      }, `projectRequest_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
